package util;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;

import play.Logger;

public class PlausabilityCalculator {

    protected static org.apache.log4j.Logger validationJobLogger = org.apache.log4j.Logger.getLogger("validationJob");

    public static int calcPlausibilityElementsInList(ArrayList<Integer> plausabilityList, int expectedAmountOfValues) {
        if (plausabilityList.size() == 0) {
            validationJobLogger.warn("AverageList is empty, correctness is 0");
            return 0;
        } else {
            int actualAmountOfValues = plausabilityList.size();
            validationJobLogger.debug("ExpectedAmountOfValues: " + expectedAmountOfValues + " ActualAmountOfValues: "
                    + actualAmountOfValues);
            try {
                int plausability = (int) (((double) actualAmountOfValues / (double) expectedAmountOfValues) * 100);
                Logger.debug("calcPlausibilityElementsInList: %s", plausability);
                return plausability;
            } catch (Exception e) {
                Logger.error(e, "CalcPlausibility failed, set plausibility to 0");
                return 0;
            }
        }
    }

}
